UWA.Class = Class = {
  create: function() {
    return function() {
      this.initialize.apply(this, arguments);
    }
  }
}

Function.prototype.bind = function(object) {
  var __method = this;
  return function() {
    return __method.apply(object, arguments);
  }
}

Function.prototype.bindAsEventListener = function(object) {
  var __method = this;
  return function(event) {
    return __method.apply(object, [event || window.event]);
  }
}

UWA.$element = function(el){
  if (el) {
    if (!el.isUwaExtended) {
      UWA.extend(el, UWA.Element);
      el.isUwaExtended = true;
    } 
    return el;
  }
}

UWA.Ajax = {
  Request: function(url, request) {
    // to check : request.data, request.postBody, request.headers, etc
    var callback = {
      success: function(o) { request.onComplete(o) } /* , failure: function(o) {}, argument: ['foo', 'bar'] */
    }
    YAHOO.util.Connect.asyncRequest(request.method, url, callback, request.parameters);
  },
  onCompleteXML: function(arg, callback, context) {
    callback(arg[0].responseXML);
  },
  onCompleteText: function(arg, callback, context) {
    callback(arg[0].responseText);
  },
  onCompleteFeed: function(arg, callback, context) {
    var feed = UWA.Utils.parseFeed(arg[0]);
    if(typeof callback == "function") callback(feed)
  },
  onCompleteJson: function(arg, callback, context) {
    try {
      eval("var j = " + arg[0].responseText);
      callback(j, context);
    } catch(e) {
      UWA.log(e);
    }
  }
}

if (typeof UWA.Element == "undefined") UWA.Element = {};
// if (typeof UWA.Element.methods == "undefined") UWA.Element.methods = {};

UWA.extend(UWA.Element, {
  
  getDimensions: function() {
		var display = this.style.display;
		if (display != 'none' && display != null) // Safari bug
		  return {width: this.offsetWidth, height: this.offsetHeight};
		// All *Width and *Height properties give 0 on elements with display none,
		// so enable the element temporarily
		var els = this.style;
		var originalVisibility = els.visibility;
		var originalPosition = els.position;
		var originalDisplay = els.display;
		els.visibility = 'hidden';
		els.position = 'absolute';
		els.display = 'block';
		var originalWidth = this.clientWidth;
		var originalHeight = this.clientHeight;
		els.display = originalDisplay;
		els.position = originalPosition;
		els.visibility = originalVisibility;
		return {width: originalWidth, height: originalHeight};
	},
  hide: function() {
   return this.setStyle('display', 'none');
  },
  show: function() {
    return this.setStyle('display', '');
  },
  toggle: function() {
    if(this.style.display == 'none') {
      this.style.display = '';
    } else {
      this.style.display = 'none';
    }
  },
  remove: function() {
    return this.parentNode.removeChild(this);
  },
  setStyle: function(arg1, arg2) {
    return YAHOO.util.Dom.setStyle(this, arg1, arg2);
  },
  hasClassName: function(className) {
   return YAHOO.util.Dom.hasClass(this, className);
  },
  addClassName: function(className) {
    return YAHOO.util.Dom.addClass(this, className);
  },
  removeClassName: function(className) {
    return YAHOO.util.Dom.removeClass(this, className);
  },
  getElementsByClassName: function(className) {
    return YAHOO.util.Dom.getElementsByClassName(className, false, this);
  }
  
});

// Compatibility with prototype style (TabView)

if (typeof Element == "undefined") var Element = {};

Element.addClassName = function(el, className) {
  return YAHOO.util.Dom.addClass(el, className);
}
Element.removeClassName = function(el, className) {
  return YAHOO.util.Dom.removeClass(el, className);
}
Element.show = function(el) {
  return el.style.display == '';
}
Element.hide = function(el) {
  return el.style.display == 'none';
}
document.getElementsByClassName = function(className) {
  return YAHOO.util.Dom.getElementsByClassName(className);
}

function $(el) {
  if(typeof el == 'string') el = document.getElementById(el);
  return el;
}